<div class="overlay"></div>
<div class="center-wrapper">
  <div class="center-content">
    <div class="row no-m">
      <div class="col-xs-10 col-xs-offset-1 col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4">
        <section class="panel bg-white no-b fadeIn animated">
          <header class="panel-heading no-b text-center" style="font-size:30px;">
            <%= sails.config.system.AppName %>
          </header>
          <div class="p15">
            <form id="loginForm" action="/private/login/doLogin" data-parsley-validate="" novalidate="" role="form"
                  method="post">
              <input type="hidden" id="captcha" name="captcha">

              <div class="form-group">
                <input type="text" id="username" name="username" value="superadmin" required
                       class="form-control input-lg mb25"
                       placeholder="<%=sails.__('private.login.username')%>">
              </div>
              <div class="form-group">
                <input type="password" id="password" name="password" value="1" required
                       class="form-control input-lg mb25"
                       placeholder="<%=sails.__('private.login.password')%>">
              </div>
              <p id="tip" class="bg-danger p15" style="display:none"></p>
              <div class="show">
                <button class="btn btn-primary btn-lg btn-block" type="submit" data-loading-text="<%=sails.__('private.login.loading')%>...">
                  <%=sails.__('private.login.load')%>
                </button>
              </div>
            </form>
          </div>
        </section>
        <p class="text-center text-default">
          Copyright &copy;
          <span id="year" class="mr5"></span>
          <span><%= sails.config.system.AppCopyright %></span>
        </p>
      </div>
    </div>

  </div>
</div>
<!-- 验证码 -->
<div id="dialogVeryCode" class="modal fade bs-modal-sm" tabindex="-3" role="dialog" aria-hidden="false">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title" style="color:black;"><%=sails.__('private.login.inputverifycode')%>
        </h4>
      </div>
      <div class="modal-body">
        <form id="f2" onsubmit="return false;" data-parsley-validate="" novalidate="">
          <div class="row">
            <div class="col-xs-2"></div>
            <div class="col-xs-6">
              <input type="text" id="verifycode" required class="form-control input-lg"
                     placeholder="<%=sails.__('private.login.verifycode')%>">
            </div>
            <div class="col-xs-4">
              <img id="captcha_img" src="/private/login/captcha" style="height:46px;cursor: pointer;"
                   onclick="$('#captcha_img').attr('src', '/private/login/captcha?_=' + new Date().getTime())"/>
            </div>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button id="ok" type="button" class="btn btn-primary" data-dismiss="modal"><%=sails.__('private.login.load')%>
        </button>
      </div>
    </div>
  </div>
</div>

<script type="text/javascript">
  $(document).ready(function () {
    $("#year").html(new Date().getFullYear());
    $("#loginForm").ajaxForm({
      dataType: 'json',
      beforeSubmit: function (arr, form, options) {
        form.find("button:submit").text("<%=sails.__('private.login.loading')%>...");
        form.find("button:submit").attr("disabled", "disabled");
      },
      success: function (data, statusText, xhr, form) {
        if (data.code == 0) {
          $("#tip").hide();
          form.find("button:submit").text("<%=sails.__('private.login.load')%>");
          window.location.href = "/sysadmin/home";
        } else if (data.code == 2) {
          $("#verifycode").val("");
          $("#dialogVeryCode img").attr("src", '/private/login/captcha?_=' + new Date().getTime());
          return $("#dialogVeryCode").modal({show: true,backdrop: 'static', keyboard: false});
        } else {
          $("#captcha").val("");
          $('#captcha_img').attr('src', '/private/login/captcha?_=' + new Date().getTime());
          $("#tip").html(data.msg);
          $("#tip").fadeIn();
          form.find("button:submit").text("<%=sails.__('private.login.load')%>");
          form.find("button:submit").removeAttr("disabled")
        }
      }
    });
    $("#ok").on("click", function () {
      if ($("#verifycode").val() == "") {
        $("#f2").submit();
        return false;
      }
      $("#captcha").val($("#verifycode").val());
      $("#loginForm").submit();
    });
    $("#dialogVeryCode").on("keypress",function (event) {
        var key = event.which;
        if (key == 13) {
          $("#ok").trigger("click");
        }
    });
    $("#username").focus();
  });
</script>
